import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:seedfour/app/theme.dart';
import 'package:seedfour/toolkit/typedef/function.dart';

import '../../../../constants.dart';
import '../state.dart';

class NoticeInfoWidget extends StatelessWidget {
  final ParamSingleCallback onLongPress;

  const NoticeInfoWidget({
    Key? key,
    required this.data,
    required this.onLongPress,
  }) : super(key: key);

  final NoticeDetailState data;

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.symmetric(horizontal: kSpaceSmall),
      padding: EdgeInsets.all(kSpaceMedium),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(kRadiusMedium),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            data.noticeData.value.title ?? '',
            style: TextStyle(
              fontSize: kFontSizeMedium,
              color: AppColor.colorFontBlack,
              fontWeight: AppFont.fontMedium,
            ),
          ),
          SizedBox(height: kSpaceMini),
          InkWell(
            onLongPress: () => onLongPress(data.noticeData.value.content),
            child: Text(
              data.noticeData.value.content ?? '',
              style: TextStyle(
                fontSize: kFontSizeSmall,
                color: AppColor.colorFontBlack,
              ),
            ),
          ),
          SizedBox(height: kSpaceLarge),
          Text(
            '标的额',
            style: TextStyle(
              fontSize: kFontSizeMedium,
              color: AppColor.colorFontBlack,
              fontWeight: AppFont.fontMedium,
            ),
          ),
          SizedBox(height: kSpaceMini),
          Text(
            data.noticeData.value.subjectAmount ?? '无',
            style: TextStyle(
              fontSize: kFontSizeSmall,
              color: AppColor.colorFontBlack,
            ),
          ),
          SizedBox(height: kSpaceLarge),
          Text(
            '服务价格',
            style: TextStyle(
              fontSize: kFontSizeMedium,
              color: AppColor.colorFontBlack,
              fontWeight: AppFont.fontMedium,
            ),
          ),
          SizedBox(height: kSpaceMini),
          Text(
            data.noticeData.value.servicePrice ?? '无',
            style: TextStyle(
              fontSize: kFontSizeSmall,
              color: AppColor.colorFontBlack,
            ),
          ),
          SizedBox(height: kSpaceLarge),
          Text(
            '案源比例',
            style: TextStyle(
              fontSize: kFontSizeMedium,
              color: AppColor.colorFontBlack,
              fontWeight: AppFont.fontMedium,
            ),
          ),
          SizedBox(height: kSpaceMini),
          Text(
            '${data.noticeData.value.cooperRatio}%',
            style: TextStyle(
              fontSize: kFontSizeSmall,
              color: AppColor.colorFontBlack,
            ),
          ),

          if (data.noticeData.value.status ==
              data.noticeStatus.keys.elementAt(1)) ...[
            SizedBox(height: kSpaceLarge),
            Text(
              '发布人',
              style: TextStyle(
                fontSize: kFontSizeMedium,
                color: AppColor.colorFontBlack,
                fontWeight: AppFont.fontMedium,
              ),
            ),
            SizedBox(height: kSpaceMini),
            Text(
              data.noticeData.value.name ?? '',
              style: TextStyle(
                fontSize: kFontSizeSmall,
                color: AppColor.colorFontBlack,
              ),
            ),
            SizedBox(height: kSpaceLarge),
            Text(
              '联系方式',
              style: TextStyle(
                fontSize: kFontSizeMedium,
                color: AppColor.colorFontBlack,
                fontWeight: AppFont.fontMedium,
              ),
            ),
            SizedBox(height: kSpaceMini),
            Row(
              children: [
                Expanded(
                  child: Text(
                    '${data.noticeData.value.phoneNumber ?? ''}(当事人)',
                    style: TextStyle(
                      fontSize: kFontSizeSmall,
                      color: AppColor.colorFontBlack,
                    ),
                  ),
                ),
                IconButton(
                  icon: const Icon(Icons.copy, size: 18),
                  onPressed: () {
                    Clipboard.setData(
                      ClipboardData(
                          text: data.noticeData.value.phoneNumber ?? ''),
                    );
                    ScaffoldMessenger.of(context).showSnackBar(
                      const SnackBar(content: Text('已复制当事人联系方式')),
                    );
                  },
                ),
              ],
            ),
            Row(
              children: [
                Expanded(
                  child: Text(
                    '${data.noticeData.value.ownerMobile ?? ''}(发布人)',
                    style: TextStyle(
                      fontSize: kFontSizeSmall,
                      color: AppColor.colorFontBlack,
                    ),
                  ),
                ),
                IconButton(
                  icon: const Icon(Icons.copy, size: 18),
                  onPressed: () {
                    Clipboard.setData(
                      ClipboardData(
                          text: data.noticeData.value.ownerMobile ?? ''),
                    );
                    ScaffoldMessenger.of(context).showSnackBar(
                      const SnackBar(content: Text('已复制发布人联系方式')),
                    );
                  },
                ),
              ],
            ),
          ],

          // 未领取状态显示联系方式
          if (data.noticeData.value.status ==
              data.noticeStatus.keys.elementAt(0)) ...[
            SizedBox(height: kSpaceLarge),
            Text(
              '联系方式',
              style: TextStyle(
                fontSize: kFontSizeMedium,
                color: AppColor.colorFontBlack,
                fontWeight: AppFont.fontMedium,
              ),
            ),
            SizedBox(height: kSpaceMini),
            Text(
              '领取后可以获得联系方式',
              style: TextStyle(
                fontSize: kFontSizeSmall,
                color: AppColor.colorFontBlack,
              ),
            ),
          ],
        ],
      ),
    );
  }
}
